package com.ljh.controller;

import com.ljh.mapper.OrderMapper;
import com.ljh.pojo.Order;
import com.ljh.pojo.OrderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderMapper orderMapper;
    @GetMapping("/deleteByUid/{uid}")
    public void deleteByUid(@PathVariable("uid") long uid){
        orderMapper.deleteByUid(uid);
    }
    @PostMapping("/save")
    public void save(@RequestBody Order order){
         orderMapper.save(order);
    }
    @GetMapping("/findAllByUid/{uid}/{page}/{limit}")
    public OrderVO findAllByUid(@PathVariable("uid") long uid, @PathVariable("page") int page, @PathVariable("limit") int limit){
        OrderVO orderVO = new OrderVO();
        orderVO.setCode(0);
        orderVO.setMsg("");
        orderVO.setCount(orderMapper.countByUid(uid));
        orderVO.setData(orderMapper.findAllByUid(uid,(page-1)*limit,limit));
        return orderVO;
    }

    @GetMapping("/deleteByMid/{mid}")
    public void deleteByMid(@PathVariable("mid") long mid){
        orderMapper.deleteByMid(mid);
    }
    @GetMapping("/findAllByState/{state}/{page}/{limit}")
    public OrderVO findAllByState(@PathVariable("state") int state,@PathVariable("page") int page,
                                  @PathVariable("limit") int limit){
        OrderVO orderVO=new OrderVO();
        orderVO.setCode(0);
        orderVO.setMsg("");
        orderVO.setCount(orderMapper.countByState(state));
        orderVO.setData(orderMapper.findAllByState(state,(page-1)*limit,limit));
        return orderVO;
    }
    @RequestMapping("/update/{id}/{aid}/{state}")
    public void updateState(@PathVariable("id") long id,@PathVariable("aid") long aid,
                            @PathVariable("state") int state){
        orderMapper.updateState(id,aid,state);
    }
}
